#pragma once

#include "my_mem.h"
#include "my_syscall.h"
#include "my_rbtree.h"

typedef struct my_thread_base_s my_thread_base_t;

typedef void (*my_thread_base_execute_pt)(my_thread_base_t *thread_base);

struct my_thread_base_s {
    my_thread_base_execute_pt           execute_pt;
    void                                *data;
    my_thread_t                         tid;
    my_mem_pool_t                       *mem_pool;
    my_4kaligned_mem_pool_t             *aligned_mem_pool;
    my_rbtree_t                         store_rbtree;
    my_rbtree_node_t                    store_rbtree_sentinel;
};

void my_thread_base_start(my_thread_base_t *thread_base,
    my_thread_base_execute_pt execute_pt, void *data,
    int64_t mem_pool_water_level, int64_t aligned_mem_pool_water_level);

void my_thread_base_join(my_thread_base_t *thread_base, void *ret);

my_thread_base_t *current_thread_base();

void *my_thread_malloc(int64_t size);

void *my_thread_calloc(int64_t size);

void my_thread_free(void *ptr);

void *my_thread_aligned_malloc(int64_t size);

void *my_thread_aligned_calloc(int64_t size);

void my_thread_aligned_free(void *ptr);

void my_thread_store_put(const char *name, void *value);

void my_thread_store_safe_put(const char *name, void *value);

void *my_thread_store_get(const char *name);

void my_thread_store_del(const char *name);